package hk.m4s.lr.repair.test.ui.user;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import framework.common.Constant;
import framework.common.baseui.UeBaseActivity;
import framework.utils.SharedPreferencesUtils;
import hk.m4s.lr.repair.test.R;
import hk.m4s.lr.repair.test.ui.equipment.DeviceRepairActivity;
import hk.m4s.lr.repair.test.ui.equipment.DeviceRequestsActivity;
import hk.m4s.lr.repair.test.ui.webview.WebViewActivity;
import hk.m4s.lr.repair.test.utils.SharedPreferencesUtil;
import hk.m4s.lr.repair.test.utils.ToastUtil;

/**
 * Created by qi.wang on 2017/3/23.
 * 消息中心
 */

public class NoticeActivity extends UeBaseActivity implements View.OnClickListener{
    private RelativeLayout click_xitong,click_yewu;
    private TextView xitong_num,yewu_num;
    private Context context;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        baseSetContentView(R.layout.activity_notice);
        hiddenFooter();
        showGoBackBtn();
        setTitleText("消息中心");
        context=this;
        findBaseView();

    }
    public void findBaseView(){
        click_xitong=(RelativeLayout)findViewById(R.id.click_xitong);
        click_yewu=(RelativeLayout)findViewById(R.id.click_yewu);
        xitong_num=(TextView) findViewById(R.id.xitong_num);
        yewu_num=(TextView) findViewById(R.id.yewu_num);
        click_xitong.setOnClickListener(this);
        click_yewu.setOnClickListener(this);
        String sysNotice=getIntent().getStringExtra("sysNotice");
        String businessNotice=getIntent().getStringExtra("businessNotice");
        if(SharedPreferencesUtils.getSharedPreferences(Constant.ifadmin,"").equals("2")) {
            click_yewu.setVisibility(View.VISIBLE);
        }else{
            click_yewu.setVisibility(View.GONE);
        }
        if(sysNotice!=null) {
            if (Integer.parseInt(sysNotice) > 0) {
                xitong_num.setBackgroundResource(R.mipmap.message_yes);
                xitong_num.setText(sysNotice);
            } else {
                xitong_num.setBackgroundResource(R.mipmap.message_no);
                xitong_num.setText("无");
            }
        }else{
            xitong_num.setBackgroundResource(R.mipmap.message_no);
            xitong_num.setText("无");
        }
        if(businessNotice!=null) {
            if (Integer.parseInt(businessNotice) > 0) {
                yewu_num.setBackgroundResource(R.mipmap.message_yes);
                yewu_num.setText(businessNotice);
            } else {
                yewu_num.setBackgroundResource(R.mipmap.message_no);
                yewu_num.setText("无");
            }
        }else{
            yewu_num.setBackgroundResource(R.mipmap.message_no);
            yewu_num.setText("无");
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.click_xitong:
                Intent aboutIntent=new Intent(NoticeActivity.this, UserNoticeActivity.class);
                aboutIntent.putExtra("title","系统消息");
                startActivity(aboutIntent);
                break;
            case R.id.click_yewu:
                if(SharedPreferencesUtil.getInstance().getString("members_id")==null||SharedPreferencesUtil.getInstance().getString("members_id").equals("")){
                    ToastUtil.toast(context,"非企业用户不能使用");
                }else {
                    Intent yewuIntent = new Intent(NoticeActivity.this, DeviceRequestsActivity.class);
                    startActivity(yewuIntent);
                }
                break;
        }
    }
}
